- add_to_breadcrumbs _("Users"), admin_users_path
- breadcrumb_title @user.name
- page_title @user.name, _("Users")
- list_item_classes = '!gl-grid @md/panel:gl-grid-cols-3 gl-gap-x-3'
= render 'admin/users/head'

.row
  .gl-col-md-6
    = render Pajamas::CardComponent.new(card_options: { class: 'gl-mb-5' }, body_options: { class: 'gl-py-2'}) do |c|
      - c.with_header do
        = @user.name
      - c.with_body do
        %ul.content-list
          %li
            = render Pajamas::AvatarComponent.new(@user, size: 64, class: 'gl-mr-3')
          %li
            %span.gl-text-subtle= _('Profile page:')
            %strong
              = link_to user_path(@user) do
                = @user.username
    -# Rendered on mobile only so order of cards can be different on desktop vs mobile
    %div{ class: "@md/panel:gl-hidden" }
      = render 'admin/users/profile', user: @user
      = render 'admin/users/user_detail_note'
    = render Pajamas::CardComponent.new(card_options: { class: 'gl-mb-5' }, body_options: { class: 'gl-py-2'}) do |c|
      - c.with_header do
        = _('Account')
      - c.with_body do
        %ul.content-list
          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('Name:')
            .gl-col-span-2
              %strong= @user.name
          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('Username:')
            .gl-col-span-2
              %strong= @user.username
          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('Email:')
            .gl-col-span-2
              %strong= render partial: 'shared/email_with_badge', locals: { email: mail_to(@user.email), verified: @user.confirmed? }

          %li{ class: list_item_classes, data: { testid: 'email-confirmation-code-last-sent-at' } }
            %span.gl-text-subtle= s_('UserProfile|Email confirmation code last sent at:')
            .gl-col-span-2
              %strong= @user.confirmation_sent_at&.to_fs(:medium) || _('never')
              - if email_verification_token_expired?(email_sent_at: @user.confirmation_sent_at )
                %span= _('(code expired)')
          %li{ class: list_item_classes, data: { testid: 'email-verification-code-last-sent-at' } }
            %span.gl-text-subtle= s_('UserProfile|Locked account email verification code last sent at:')
            .gl-col-span-2
              %strong= @user.locked_at&.to_fs(:medium) || _('never')
              - if email_verification_token_expired?(email_sent_at: @user.locked_at)
                %span= _('(code expired)')

          - @user.emails.reject(&:user_primary_email?).each do |email|
            %li{ class: list_item_classes }
              %span.gl-text-subtle= _('Secondary email:')
              .gl-col-span-2
                %strong= render partial: 'shared/email_with_badge', locals: { email: email.email, verified: email.confirmed? }
                - if can?(current_user, :admin_all_resources)
                  = link_button_to nil, remove_email_admin_user_path(@user, email), data: { confirm: _("Are you sure you want to remove %{email}?") % { email: email.email }, 'confirm-btn-variant': 'danger' }, method: :delete, class: 'gl-float-right has-tooltip', title: _('Remove secondary email'), id: "remove_email_#{email.id}", category: :tertiary, size: :small, icon: 'remove'
          %li{ class: list_item_classes }
            %span.gl-text-subtle ID:
            .gl-col-span-2
              %strong{ data: { testid: 'user-id-content' } }= @user.id
          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('Namespace ID:')
            .gl-col-span-2
              %strong= @user.namespace_id

          - if @user.placeholder?
            - placeholder_group = Import::SourceUser.for_placeholder_user(@user)&.take&.namespace
            %li{ class: list_item_classes }
              %span.gl-text-subtle= s_('UserMapping|Placeholder top-level group:')
              .gl-col-span-2
                %strong
                  - if placeholder_group
                    = link_to placeholder_group.name, admin_group_path(placeholder_group)
                  - else
                    = _('None')

          %li.two-factor-status{ class: list_item_classes }
            %span.gl-text-subtle= _('Two-factor Authentication:')
            .gl-col-span-2
              %strong{ class: @user.two_factor_enabled? ? 'gl-text-success' : 'gl-text-danger' }
                - if @user.two_factor_enabled?
                  = _('Enabled')
                  - if current_user.admin?
                    = link_button_to _('Disable'), disable_two_factor_admin_user_path(@user), aria: { label: _('Disable') }, data: { confirm: _('Are you sure?'), 'confirm-btn-variant': 'danger' }, method: :patch, class: 'gl-float-right', title: _('Disable Two-factor Authentication'), variant: :danger, size: :small
                - else
                  = _('Disabled')

          = render_if_exists 'admin/namespace_plan_info', namespace: @user.namespace

          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('External User:')
            .gl-col-span-2
              %strong= @user.external? ? _('Yes') : _('No')

          = render_if_exists 'admin/users/provisioned_by', user: @user
          = render_if_exists 'admin/users/enterprise_group', user: @user

          %li{ class: list_item_classes, 'data-testid': 'admin-can-create-top-level-groups' }
            %span.gl-text-subtle= _('Can create top-level groups:')
            .gl-col-span-2
              %strong= @user.allow_user_to_create_group_and_project? && @user.can_create_group? ? _('Yes') : _('No')
          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('Private profile:')
            .gl-col-span-2
              %strong= @user.private_profile ? _('Yes') : _('No')
          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('Personal projects limit:')
            .gl-col-span-2
              %strong= @user.projects_limit
          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('Member since:')
            .gl-col-span-2
              %strong= @user.created_at.to_fs(:medium)
          - if @user.confirmed_at
            %li{ class: list_item_classes }
              %span.gl-text-subtle= _('Confirmed at:')
              .gl-col-span-2
                %strong= @user.confirmed_at.to_fs(:medium)
          - else
            %li{ class: list_item_classes }
              %span.gl-text-subtle= _('Confirmed:')
              .gl-col-span-2
                %strong.gl-text-danger= _('No')

          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('Current sign-in IP:')
            .gl-col-span-2
              %strong= @user.current_sign_in_ip || _('never')

          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('Current sign-in at:')
            .gl-col-span-2
              %strong= @user.current_sign_in_at&.to_fs(:medium) || _('never')

          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('Last sign-in IP:')
            .gl-col-span-2
              %strong= @user.last_sign_in_ip || _('never')

          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('Last sign-in at:')
            .gl-col-span-2
              %strong= @user.last_sign_in_at&.to_fs(:medium) || _('never')

          %li{ class: list_item_classes }
            %span.gl-text-subtle= _('Sign-in count:')
            .gl-col-span-2
              %strong= @user.sign_in_count

          %li{ class: list_item_classes }
            %span.gl-text-subtle= _("Highest role:")
            .gl-col-span-2
              %strong= Gitlab::Access.human_access_with_none(@user.highest_role)

          %li{ class: list_item_classes }
            %span.gl-text-subtle= s_("Profiles|Support Pin:")
            .gl-col-span-2
              %strong
                = @user.support_pin || _('None')

          %li{ class: list_item_classes }
            %span.gl-text-subtle= s_("Profiles|Support Pin expires at:")
            .gl-col-span-2
              %strong
                - if @user.support_pin_expires_at
                  = @user.support_pin_expires_at.to_fs(:medium)
                - else
                  = _('None')


          = render_if_exists 'admin/users/using_license_seat', user: @user

          - if @user.ldap_user?
            %li{ class: list_item_classes }
              %span.gl-text-subtle= _('LDAP uid:')
              .gl-col-span-2
                %strong= @user.ldap_identity.extern_uid

          - if @user.created_by
            %li{ class: list_item_classes }
              %span.gl-text-subtle= _('Created by:')
              .gl-col-span-2
                %strong= link_to @user.created_by.name, [:admin, @user.created_by]

          = render_if_exists 'namespaces/shared_runner_status', namespace: @user.namespace, list_item_classes: list_item_classes

    = render_if_exists 'admin/users/credit_card_info', user: @user, link_to_match_page: true

    = render_if_exists 'admin/users/phone_info', user: @user, link_to_match_page: true

    = render 'shared/custom_attributes', custom_attributes: @user.custom_attributes

  -# Rendered on desktop only so order of cards can be different on desktop vs mobile
  .gl-col-md-6.gl-hidden{ class: "@md/panel:gl-block" }
    = render 'admin/users/profile', user: @user
    = render 'admin/users/user_detail_note'
